/*
 * 中北大学软件学院版权所有2020-2025
 */
package nuc.lp.uolab.department.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import nuc.lp.uolab.department.vo.Dept;
import nuc.lp.uolab.department.vo.Major;
import nuc.lp.uolab.util.DbUtil;

/**
 * DeptDao实现类
 * @author liupeng
 * @version 1.0
 */
public class DeptDaoImpl implements DeptDao{

	@Override
	public int insertDept(Dept dept) {
		Connection connection = DbUtil.getConnection();
		PreparedStatement pstatement = null;
		int flag = 0;
		
		String sql = "INSERT INTO t_department VALUES(?,?,?)";
		try {
			pstatement = connection.prepareStatement(sql);
			pstatement.setInt(1, dept.getDid());
			pstatement.setString(2, dept.getDname());
			pstatement.setString(3, dept.getRemark());
			flag = pstatement.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			DbUtil.closeResource(connection, pstatement, null);
		}

		return flag;
	}

	@Override
	public int insertMajor(Major major) {
		int flag = 0;
		Connection connection = DbUtil.getConnection();
		PreparedStatement pStatement = null;
		
		String sql = "INSERT INTO t_major VALUES(?,?,?,?)";
		try {
			pStatement = connection.prepareStatement(sql);
			pStatement.setInt(1, major.getMajorId());
			pStatement.setInt(2, major.getDid());
			pStatement.setString(3, major.getMajorName());
			pStatement.setString(4, major.getRemark());
			flag = pStatement.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			DbUtil.closeResource(connection, pStatement, null);
		}
		return flag;
	}

}
